//
//  NWLoginRequest.m
//  KuWoCan
//
//  Created by hwd on 17/3/21.
//  Copyright © 2017年 hwd. All rights reserved.
//

#import "NWLoginRequest.h"
#import "AFNetworking.h"
@implementation NWLoginRequest


- (void)startRequestLoginWithLoginName:(NSString *)loginName password:(NSString *)password
{
    _showError = YES;
    _showLoading = YES;
    _path = NWLogin_Path;
    
    //18088888888   654321    供应商
    //18000000000   123456
    NSMutableDictionary *dic = [[NSMutableDictionary alloc]initWithDictionary:@{@"loginName":loginName,@"password":password}];
    
    _params = dic;
    [self startPost];
}


- (void)startRequestChangePasswordWithId:(NSString *)userId password:(NSString *)password newPassword:(NSString *)newPassword loginName:(NSString *)loginName
{
    _showError = YES;
    _showLoading = YES;
    _path = NWChangePassWord_Path;
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc]initWithDictionary:@{@"id":userId,@"password":password,@"newPassword":newPassword,@"loginName":loginName}];
    
    _params = dic;
    [self startPost];
}

- (void)startRequestGetUserInfoWithId:(NSString *)userId
{
    _showError = YES;
    _showLoading = YES;
    _path = NWGetUserInfo_Path;
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc]initWithDictionary:@{@"userId":userId}];
    
    _params = dic;
    [self startPost];
}

/*
 id	string	是	用户信息Id	1
 realName	string	是	真实姓名
 acreage	string	是	面积
 car	string	是	车辆数
 teams	string	是	团队
 salesArea	string	是	销售区域
 salesChannel	string	是	销售渠道
 brand	string	是	经营品牌
 experience	string	是	行业经验
 registeredCapital	string	是	注册资金
 bankName	string	是	银行名称
 bankCard	string	是	银行卡号
 businessLicense	string	是	营业执照
 foodCertificate	string	是	食品合格证
 */

- (void)startRequestChangeChangeUserInfoWithDic:(NSMutableDictionary *)dic
{
    _showError = YES;
    _showLoading = YES;
    _path = NWChangeUserInfo_Path;
    _params = dic;
    [self startPost];
}

//修改签名
- (void)startRequestChangeSignatureWithId:(NSString *)userId autograph:(NSString *)autograph
{
    _showError = YES;
    _showLoading = YES;
    _path = NWUpdateAutograph_Path;
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc]initWithDictionary:@{@"id":userId, @"autograph":autograph}];
    
    _params = dic;
    [self startPost];
}


//获取我的等级
//post通用接口
+(void)PostrequestUrl:(NSString *)url Dic:(NSDictionary *)dic   completion:(void (^)(NSDictionary *responseDic))complete
{
    //    NSString *urlStringUTF8 = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    manager.requestSerializer = [AFHTTPRequestSerializer serializer];
    [manager POST:url parameters:dic constructingBodyWithBlock:^(id  _Nonnull formData) {
    } progress:^(NSProgress * _Nonnull uploadProgress) {
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSDictionary *jsonDic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves error:nil];
        if (complete) {
            complete(jsonDic);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        // 请求失败
        NSDictionary *dic = [[NSDictionary alloc]initWithObjectsAndKeys:@"0",@"success", nil];
        if (complete) {
            complete(dic);
        }
    }];
}


@end
